<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>驳回申购单</title>
    <script type="text/javascript">
      var type = '<%= params[:type] %>'
      Ext.onReady(function(){
              var rejectDS = new Ext.data.Store({
                proxy:new Ext.data.HttpProxy({url:'/reject/getRejectReason'}),
                reader:new Ext.data.JsonReader({
                }, [

                  {name:'id'},
                  {name:'reson'}

                ])
              });
              var id = <%= params[:id] %>;
              var rejectPurchaseForm=new Ext.form.FormPanel({
                    width:400,
                    //labelAlign: 'top',
                    
                    buttonAlign:'center',
                    autoHeight:true,
                    fileUpload: true,
                    bodyStyle: 'padding:5px',
                    labelWidth:100,
                    waitMsgTarget: true,
                    frame: true,
                    items:[{
                          layout:'column',
                          items:[{
                              columnWidth:1,
                              layout:'form',
                              labelAlign: 'top',
                              items:[{
                                  xtype:'combo',
                                  fieldLabel: '驳回原因',
                                  store: rejectDS,
                                  displayField:'reson',
                                  hiddenName:'reson',
                                  valueField:'reson',
                                  typeAhead: true,
                                  allowBlank:false,
                                  minChars:10,
                                  anchor: '95%',
                                  mode: 'remote',
                                  forceSelection: false,
                                  triggerAction: 'all',
                                  selectOnFocus:true
                              }]
                          }]
                     }],
                     buttons:[{
                        id:'reject',
                        text:'确定',
                        handler: function(){
                            var url;
                            if (type == 'dept'){
                              url = '/purchase/deptRejectPurchase?id='+id
                            }else if(type == 'auditor'){
                              url = '/purchase/rejectPurchase?id='+id
                            }else if(type == 'primary'){
                              url = '/purchase/rejectPrimary?id='+id
                            }
                            // check form value
                            if (rejectPurchaseForm.form.isValid()) {
                              
                                Ext.MessageBox.confirm('警告','确定驳回该申购单？',function(button){
                                  if(button=='yes'){
                                      var reject = Ext.getCmp('reject');
                                      reject.setDisabled(true);
                                      rejectPurchaseForm.form.submit({
                                        method: 'post',
                                        url:url,
                                        waitMsg: '正在保存驳回原因...',
                                        success: function(result, response){
                                          if (response.result.info == "success") {
                                            //添加成功后，隐藏窗口，并刷新Grid
                                            Ext.MessageBox.alert('消息', '已经成功驳回申购单');
                                            rejectWin.destroy();
                                            if (type == 'dept'){
                                              purchaseViewWin.destroy();
                                            }else if(type == 'auditor'){
                                              purchaseForReleaseWin.destroy();
                                            }else if(type == 'primary'){
                                              purchaseForAuditorWin.destroy();
                                            }
                                            
                                          }else {
                                            reject.setDisabled(false);
                                            Ext.MessageBox.alert('消息', response.result.info);
                                          }
                                        },
                                        failure: function(result, response){
                                          reject.setDisabled(false);
                                          Ext.MessageBox.alert('提示', result.responseText);
                                        }
                                      });
                                  }
                               })
                            }else {
                              Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                            }
                          }
                    },{
                        text:'取消',
                        handler:function(){
                            rejectWin.destroy();
                        }
                    }]
                });
          rejectPurchaseForm.render('reject_purchase_form');
      })
    </script>
  </head>
  <body>
     <div id="reject_purchase_form"></div>
  </body>
</html>
